package com.common.base;

import java.io.Serializable;

/**
 * @author Administrator
 */
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = 3637122497350396679L;

    private boolean success;

    private String msg;

    private T data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ResponseResult(boolean success) {
        this(success, "");
    }

    public ResponseResult(boolean success, String msg) {
        this(success, msg, null);
    }

    public ResponseResult(boolean success, String msg, T data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 返回正确结果不带数据
     *
     * @return
     */
    public static ResponseResult<Object> ok() {
        return new ResponseResult<Object>(true);
    }

    /**
     * 返回正确结果带数据
     *
     * @return
     */
    public static ResponseResult<Object> ok(String msg, Object data) {
        return new ResponseResult<Object>(true,msg,data);
    }

    /**
     * 返回正确结果带数据
     *
     * @return
     */
    public static ResponseResult<Object> ok(Object data, String msg) {
        return new ResponseResult<Object>(true,msg,data);
    }

    /**
     * 返回错误的结果带错误信息
     *
     * @param msg
     * @return
     */
    public static ResponseResult<Object> error(String msg) {
        return new ResponseResult<Object>(false, msg);
    }
}